<template>
  <ResourceItem
    icon="cpu"
    title="CPU Request"
    :content="data?.cpuRequestTotal + ' 核'"
  />
  <ResourceItem
    style="margin-left: 16px"
    icon="ram"
    title="内存 Request"
    :content="convertBytesToGbytes(data?.memoryRequestTotal) + ' G'"
  />
  <ResourceItem
    style="margin-left: 16px"
    icon="ram"
    title="内存 Limit"
    :content="convertBytesToGbytes(data?.memoryLimitTotal) + ' G'"
  />
  <ResourceItem
    style="margin-left: 16px"
    icon="storage"
    title="磁盘使用量"
    :content="convertBytesToGbytes(data?.fsUsage) + ' G'"
  />
  <ResourceItem
    style="margin-left: 16px"
    icon="cpu"
    title="CPU 使用量"
    :content="data?.cpuUsage + ' 核'"
  />
  <ResourceItem
    style="margin-left: 16px"
    icon="ram"
    title="内存使用量"
    :content="convertBytesToGbytes(data?.cpuUsage) + ' 核'"
  />
</template>

<script setup>
import { ref, defineProps, toRefs, onMounted } from "vue";
import { useRoute } from "vue-router";

defineProps({
  data: {
    required: true,
    default: null,
  },
});

const route = useRoute();

function convertBytesToGbytes(bytes) {
  // 1 Gigabyte (G) = 1,073,741,824 Bytes (B)
  const gigabytes = bytes / 1073741824;
  // 使用toFixed(2)来保留两位小数
  return gigabytes.toFixed(2);
}
</script>
<style lang="scss" scoped></style>
